import { getProductList, deleteProductData, newProductData } from '@/services/modules/product'
import { defineStore } from 'pinia'
interface productState {
  productData: any[]
  totalCount: number
}
const useProductStore = defineStore('product', {
  state: (): productState => {
    return {
      productData: [],
      totalCount: 0
    }
  },
  actions: {
    async fetchProductList(goodsSize: any) {
      const productDataRes = await getProductList(goodsSize)
      this.productData = productDataRes.data.list ?? []
      this.totalCount = productDataRes.data.totalCount
    },
    async fetchDeleteProduct(id: number) {
      await deleteProductData(id)
    },
    async fetchNewProductData(newData: any) {
      const newDataRes = await newProductData(newData)
      this.fetchProductList({ offset: 0, size: 10 })
      console.log(newDataRes)
    }
  }
})

export default useProductStore
